import service from '../../services/task';
import Router from '../../utils/router';
import base from '../../config/base.js';
import ext from '../../utils/login';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    top_ba: base.static + 'task/red-ground2.png',
    icon_nored: base.static + 'task/red-nored2.png',
    icon_money: base.static + 'task/red-money3.png',
    redList: [],
    myRed: '',
    havered: false,
    nored: false,
    noauthorize: false,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showModal({
      title: '提示',
      content: '活动已结束，去我的店铺看看吧',
      showCancel: false,
      confirmText: '去逛逛',
      confirmColor: '#c41330',
      success: function(){
        Router.reLaunch('store', `store_id=${options.store_id}`);
      }
    })
    let that = this;
    that.setData({
      store_id: options.store_id,
      rdtkid: options.rdtkid
    })
    if (wx.getStorageSync("user_info").info_authorize == 1) {
      that.getredpackage(that.data.rdtkid);
    } else {
      that.setData({
        noauthorize: true,
      })
    }
  },
  //授权
  onGotUserInfo: function (e) {
    let that = this;
    let d = e.detail;
    if (d.errMsg == 'getUserInfo:ok') {
      ext.getUserInfo(d, b => {
        if (b) {
          that.setData({
            noauthorize: false,
          })
          that.getredpackage(that.data.rdtkid);
        }
      });
    }
  },
  //红包记录
  getredpackage: function (rdtkid) {
    let that = this;
    let params = {
      rdtkid: rdtkid
    }
    service.getredpackage(params, function (res) {
      if (res && res.code == 200) {
        if (res.myRed == "") {
          that.setData({
            nored: true,
            redList: res.list
          });
        } else {
          that.setData({
            havered: true,
            myRed: res.myRed,
            redList: res.list
          });
        }

      }
    });
  },
  //立即使用
  gostore: function () {
    let that = this;
    Router.go('store', `store_id=${that.data.store_id}`);
  },
  // 立即查看
  gomy: function () {
    Router.go('my');
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
   
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})